<template>
	<view>
		<view v-if="verionType === 'center'">
			<view class="jx-popup-mark" v-if="show" @tap.stop="close()">
				<view class="mark-content" @tap.stop>
					<view class="content" v-if="showSoltContent">
						<slot name="diycontent"></slot>
					</view>
					<view class="content" v-else>
						<slot name="content"></slot>
						<view class="footer-btn" v-if="!showTwoBtn">
							<view class="add-btn" @tap="optionTap('sure')">确认</view>
						</view>
						<view class="footer-btn-two" v-else>
							<view class="cancel-btn" @tap="optionTap('cancel')">取消</view>
							<view class="sure-btn" @tap="optionTap('sure')">确认</view>
						</view>
					</view>
					<view class="close-image close" @tap.stop="close()">
						<image class="img-close" src="./image/关闭.png"></image>
					</view>
				</view>
			</view>
		</view>
		<view v-if="verionType === 'bottom'">
			<view class="jx-popup-mark jx-popup-bottom-mark" v-if="show" @tap.stop="close()">
				<view class="mark-content" @tap.stop>
					<view class="content" v-if="showSoltContent">
						<slot name="diycontent"></slot>
					</view>
					<view class="content" v-else>
						<slot name="content"></slot>
						<view class="footer-btn" v-if="!showTwoBtn">
							<view class="add-btn" @tap="optionTap('sure')">确认</view>
						</view>
						<view class="footer-btn-two" v-else>
							<view class="cancel-btn" @tap="optionTap('cancel')">取消</view>
							<view class="sure-btn" @tap="optionTap('sure')">确认</view>
						</view>
					</view>
					<view class="close-image close" @tap.stop="close()">
						<image class="img-close" src="./image/关闭.png"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	/**
	 * jx-popup 简单弹框
	 * @description 简单弹框
	 * @property {String} verionType 类型 center 居中  bottom 底部 
	 * @property {Boolean} showSoltContent 是否全部自定义
	 * @property {Boolean} showTwoBtn 是否双按钮
	 * @event {Function} optionTap 点击组件触发事件
	 */
	export default {
		props: {
			showSoltContent: {
				type: Boolean,
				default: false
			},
			showTwoBtn: {
				type: Boolean,
				default: false
			},
			verionType: {
				type: String,
				default: 'center' // center 居中  bottom 底部 
			},
		},
		data() {
			return {
				show: false,
				loadObj: {}
			}
		},
		methods: {
			open(obj) {
				this.show = true
				if (obj) {
					this.loadObj = obj
				}
			},
			close() {
				this.show = false
			},
			optionTap() {
				this.$emit('optionTap', this.loadObj)
			},
		}
	}
</script>

<style lang="less" scoped>
	.jx-popup-mark {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		background-color: rgba(0, 0, 0, 0.4);
		bottom: 0;
		z-index: 9999;

		.mark-content {
			width: 90%;
			position: fixed;
			top: 50%;
			left: 50%;
			background-color: white;
			transform: translate(-50%, -50%);
			padding: 50rpx 0;
			border-radius: 20rpx;
		}

		.close {
			position: absolute;
			top: 0;
			right: 10rpx;
			font-size: 60rpx;
			color: #333;

			.img-close {
				width: 50rpx;
				height: 50rpx;
			}
		}
	}

	.jx-popup-bottom-mark {
		.mark-content {
			width: 100%;
			position: fixed;
			bottom: 0;
			top: 30%;
			left: 0;
			right: 0;
			background-color: white;
			transform: translate(0%, 0%);
			padding: 50rpx 0;
			border-radius: 20rpx;
			border-bottom-left-radius: 0;
			border-bottom-right-radius: 0;
		}
	}

	.footer-btn {
		text-align: center;
		margin-top: 20px;

		.add-btn {
			height: 90rpx;
			width: 80%;
			color: #fff;
			background-color: #F09B3F;
			border-radius: 100rpx;
			margin: 0 auto;
			margin-top: 30rpx;
			margin-bottom: 20rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}

	.footer-btn-two {
		width: 90%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 0 auto;
		margin-top: 30rpx;

		.cancel-btn {
			width: 48%;
			height: 90rpx;
			background-color: #e8e9e8;
			border-radius: 100rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.sure-btn {
			width: 48%;
			height: 90rpx;
			background-color: #F09B3F;
			border-radius: 100rpx;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
</style>